home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / src / vgaregs.h < prev    next >
Text File  |  1993-12-06  |  5KB  |  161 lines

  1. /**
  2.  ** VGAREGS.H
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. /*
  25.  * color plane operations
  26.  */
  27. #define VGA_FUNC_SET    0
  28. #define VGA_FUNC_AND    8
  29. #define VGA_FUNC_OR    16
  30. #define VGA_FUNC_XOR    24
  31.  
  32. /*
  33.  * Sequencer port and used register indices
  34.  */
  35. #define VGA_SEQUENCER_PORT    0x3c4
  36. #define VGA_SEQUENCER_DATA    0x3c5
  37.  
  38. #define VGA_WRT_PLANE_ENB_REG    2
  39.  
  40. /*
  41.  * Graphics controller port and used registers
  42.  */
  43. #define VGA_GR_CTRL_PORT    0x3ce
  44. #define VGA_GR_CTRL_DATA    0x3cf
  45.  
  46. #define VGA_SET_RESET_REG    0
  47. #define VGA_SET_RESET_ENB_REG    1
  48. #define VGA_COLOR_COMP_REG    2
  49. #define VGA_ROT_FN_SEL_REG    3
  50. #define VGA_RD_PLANE_SEL_REG    4
  51. #define VGA_MODE_REG        5
  52. #define VGA_MISC_REG        6
  53. #define VGA_COLOR_DONTC_REG    7
  54. #define VGA_BIT_MASK_REG    8
  55.  
  56. /*
  57.  * these are used from inline assembly...
  58.  */
  59. #ifdef __GNUC__
  60.   asm("L_VGA_GR_CTRL_PORT = 0x3ce");
  61.   asm("L_VGA_BIT_MASK_REG = 8");
  62.   asm("L_VGA_MODE_REG     = 5");
  63. #endif
  64.  
  65. /*
  66.  * set a VGA register
  67.  */
  68. #ifdef __GNUC__
  69. #define __SET_VGA_REG__(port,reg,value) asm volatile(             "\n\
  70.     movl    %0,%%eax                          \n\
  71.     movl    %1,%%edx                          \n\
  72.     outw    %%ax,%%dx                           "\
  73.     : /* NOTHING */                            \
  74.     : "g" (((value) << 8) | (reg)), "g" (port)            \
  75.     : "dx", "ax"                            \
  76. )
  77. #endif  /* __GNUC__ */
  78.  
  79. #ifdef  __TURBOC__
  80. #define __SET_VGA_REG__(port,reg,value) do {                \
  81.     _AX = ((value) << 8) | (reg);                    \
  82.     _DX = (port);                            \
  83.     asm out dx,ax;                            \
  84. } while(0)
  85. #endif  /* __TURBOC__ */
  86.  
  87. /*
  88.  * read a VGA register
  89.  */
  90. #ifdef __GNUC__
  91. #define __READ_VGA_REG__(port,reg,value) asm volatile(             "\n\
  92.     movl    %1,%%eax                          \n\
  93.     movl    %2,%%edx                          \n\
  94.     outb    %%al,%%dx                          \n\
  95.     incl    %%edx                              \n\
  96.     inb    %%dx,%%al                          \n\
  97.     andl    $0x000000ff,%%eax                      \n\
  98.     movl    %%eax,%0                           "\
  99.     : "=g" (value)                            \
  100.     : "g" (reg), "g" (port)                        \
  101.     : "dx", "ax"                            \
  102. )
  103. #endif  /* __GNUC__ */
  104.  
  105. #ifdef  __TURBOC__
  106. #define __READ_VGA_REG__(port,reg,value) do {                \
  107.     _AX = (reg);                            \
  108.     _DX = (port);                            \
  109.     asm out dx,al;                            \
  110.     asm inc dx;                                \
  111.     asm in  al,dx;                            \
  112.     asm xor ah,ah;                            \
  113.     (value) = _AX;                            \
  114. } while(0)
  115. #endif  /* __TURBOC__ */
  116.  
  117. /*
  118.  * Simple register settings
  119.  */
  120. #define _SetVGAWriteMode(mode) \
  121.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,_GrP4ModeReg,mode)
  122.  
  123. #define _SetVGAWritePlane(plane) \
  124.     __SET_VGA_REG__(VGA_SEQUENCER_PORT,VGA_WRT_PLANE_ENB_REG,(1 << (plane)))
  125.  
  126. #define _SetVGAPlaneMask(mask) \
  127.     __SET_VGA_REG__(VGA_SEQUENCER_PORT,VGA_WRT_PLANE_ENB_REG,(mask))
  128.  
  129. #define _SetVGAWriteAllPlanes() \
  130.     __SET_VGA_REG__(VGA_SEQUENCER_PORT,VGA_WRT_PLANE_ENB_REG,0x0f);
  131.  
  132. #define _SetVGAReadPlane(plane) \
  133.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,VGA_RD_PLANE_SEL_REG,plane)
  134.  
  135. #define _SetVGASetResetPlanes(planes) \
  136.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,VGA_SET_RESET_ENB_REG,planes)
  137.  
  138. #define _SetVGAColorFunction(func) \
  139.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,VGA_ROT_FN_SEL_REG,func)
  140.  
  141. #define _SetVGAFillData(color) \
  142.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,VGA_SET_RESET_REG,color)
  143.  
  144. #define _SetVGADontCareRegister(value) \
  145.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,VGA_COLOR_DONTC_REG,value)
  146.  
  147. #define _SetVGAWriteMask(mask) \
  148.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,VGA_BIT_MASK_REG,mask)
  149.  
  150. /*
  151.  * Somewhat more complex register settings
  152.  */
  153. #define _SetVideoColorOper(oper) \
  154.     __SET_VGA_REG__(VGA_GR_CTRL_PORT,_GrP4WriteOps[oper],0)
  155.  
  156. #define _SetVideoColor(color,oper) do {                    \
  157.     _SetVideoColorOper(oper);                        \
  158.     _SetVGAFillData(color);                        \
  159. } while(0)
  160.  
  161.